///////////////////////////////////////////////////////////////////////////////////
// File:        MultiLanguage.h
// Purpose:     Multilanguage support
// Author:      Tukero
// Copyright:   (c) Tukero <tukero@gmail.com>
// Licence:     GNU/LGPL v3
///////////////////////////////////////////////////////////////////////////////////

#ifndef _TNOD_MULTILANG_
#define _TNOD_MULTILANG_

#ifndef WX_PRECOMP
#  include <wx/wx.h>
#else
#  include <wx/wxprec.h>
#endif

#include <wx/config.h>
#include <windows.h>
#include "Settings.h"

#define GETLANG(idOfTranslatedMsg) Multilanguage::Get(idOfTranslatedMsg)

//for language management
class Multilanguage
{
private:
    static int m_languageId;
public:
    Multilanguage()
    {
        //m_languageId = wxConfig::Get()->Read(wxT("Language"),wxLANGUAGE_SPANISH);        
        //m_languageId = wxLocale::GetSystemLanguage();
        //m_languageId = GetSystemDefaultLCID();

    }
    static void Init()
    {
        m_languageId = SETTINGS->GetLanguage();
    }
    ~Multilanguage() {}
    static wxString Get(int messageId)
    {
        wxString message;
        wxChar buffer[251];       

        switch (m_languageId)
        {
        case wxLANGUAGE_ENGLISH:
            messageId += 200;
            break;
        case wxLANGUAGE_PORTUGUESE:
            messageId += 400;
            break;
        case wxLANGUAGE_ITALIAN:
            messageId += 600;
            break;
        case wxLANGUAGE_FRENCH:
            messageId += 800;
            break;
        case wxLANGUAGE_RUSSIAN:
            messageId += 1000;
            break;
        case wxLANGUAGE_TAJIK://persian (ISO-639-3)
            messageId += 1200;
            break;
        case wxLANGUAGE_UKRAINIAN:
            messageId += 1400;
            break;            
        case wxLANGUAGE_SWEDISH:
            messageId += 1600;
            break;            
        }

        int copiedBytes = LoadString(GetModuleHandle(wxT("String Table")),messageId,buffer,250);
        if (copiedBytes > 0)
            message = buffer;
        else if (messageId >= 200)
        {   //if a string is not translated, use Spanish for default
            messageId %= 200;          
            copiedBytes = LoadString(GetModuleHandle(wxT("String Table")),messageId,buffer,250);
            
            if (copiedBytes > 0)
                message = buffer;
        }

        return message;
    }
};
// -----------------------------------------------------------------------------------

#endif